﻿/**  版本信息模板在安装目录下，可自行修改。
* pro_lot_test_data.cs
*
* 功 能： N/A
* 类 名： pro_lot_test_data
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/2/28 13:08:40   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Astronergy.MES.App.Library.MySQL.DAL
{
    /// <summary>
    /// 数据访问类:pro_lot_test_data
    /// </summary>
    public partial class pro_lot_test_data
    {
        public pro_lot_test_data()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperMySQL.GetMaxID("VERSION_NO", "pro_lot_test_data");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string LOT_NUMBER, int VERSION_NO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from pro_lot_test_data");
            strSql.Append(" where LOT_NUMBER=@LOT_NUMBER and VERSION_NO=@VERSION_NO ");
            MySqlParameter[] parameters = {
					new MySqlParameter("@LOT_NUMBER", MySqlDbType.VarChar,50),
					new MySqlParameter("@VERSION_NO", MySqlDbType.Int32,11)			};
            parameters[0].Value = LOT_NUMBER;
            parameters[1].Value = VERSION_NO;

            return DbHelperMySQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into pro_lot_test_data(");
            strSql.Append("LOT_NUMBER,VERSION_NO,TTIME,EL_IMAGE,IV_IMAGE,PMAX,ISC,IPM,VOC,VPM,IS_USED)");
            strSql.Append(" values (");
            strSql.Append("@LOT_NUMBER,@VERSION_NO,@TTIME,@EL_IMAGE,@IV_IMAGE,@PMAX,@ISC,@IPM,@VOC,@VPM,@IS_USED)");
            MySqlParameter[] parameters = {
					new MySqlParameter("@LOT_NUMBER", MySqlDbType.VarChar,50),
					new MySqlParameter("@VERSION_NO", MySqlDbType.Int32,11),
					new MySqlParameter("@TTIME", MySqlDbType.Timestamp),
					new MySqlParameter("@EL_IMAGE", MySqlDbType.VarChar,255),
					new MySqlParameter("@IV_IMAGE", MySqlDbType.VarChar,255),
					new MySqlParameter("@PMAX", MySqlDbType.Decimal,18),
					new MySqlParameter("@ISC", MySqlDbType.Decimal,18),
					new MySqlParameter("@IPM", MySqlDbType.Decimal,18),
					new MySqlParameter("@VOC", MySqlDbType.Decimal,18),
					new MySqlParameter("@VPM", MySqlDbType.Decimal,18),
					new MySqlParameter("@IS_USED", MySqlDbType.VarChar,1)};
            parameters[0].Value = model.LOT_NUMBER;
            parameters[1].Value = model.VERSION_NO;
            parameters[2].Value = model.TTIME;
            parameters[3].Value = model.EL_IMAGE;
            parameters[4].Value = model.IV_IMAGE;
            parameters[5].Value = model.PMAX;
            parameters[6].Value = model.ISC;
            parameters[7].Value = model.IPM;
            parameters[8].Value = model.VOC;
            parameters[9].Value = model.VPM;
            parameters[10].Value = model.IS_USED;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update pro_lot_test_data set ");
            strSql.Append("TTIME=@TTIME,");
            strSql.Append("EL_IMAGE=@EL_IMAGE,");
            strSql.Append("IV_IMAGE=@IV_IMAGE,");
            strSql.Append("PMAX=@PMAX,");
            strSql.Append("ISC=@ISC,");
            strSql.Append("IPM=@IPM,");
            strSql.Append("VOC=@VOC,");
            strSql.Append("VPM=@VPM,");
            strSql.Append("IS_USED=@IS_USED");
            strSql.Append(" where LOT_NUMBER=@LOT_NUMBER and VERSION_NO=@VERSION_NO ");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@TTIME", MySqlDbType.Timestamp),
					new MySqlParameter("@EL_IMAGE", MySqlDbType.VarChar,255),
					new MySqlParameter("@IV_IMAGE", MySqlDbType.VarChar,255),
					new MySqlParameter("@PMAX", MySqlDbType.Decimal,18),
					new MySqlParameter("@ISC", MySqlDbType.Decimal,18),
					new MySqlParameter("@IPM", MySqlDbType.Decimal,18),
					new MySqlParameter("@VOC", MySqlDbType.Decimal,18),
					new MySqlParameter("@VPM", MySqlDbType.Decimal,18),
					new MySqlParameter("@IS_USED", MySqlDbType.VarChar,1),
					new MySqlParameter("@LOT_NUMBER", MySqlDbType.VarChar,50),
					new MySqlParameter("@VERSION_NO", MySqlDbType.Int32,11)};
            parameters[0].Value = model.TTIME;
            parameters[1].Value = model.EL_IMAGE;
            parameters[2].Value = model.IV_IMAGE;
            parameters[3].Value = model.PMAX;
            parameters[4].Value = model.ISC;
            parameters[5].Value = model.IPM;
            parameters[6].Value = model.VOC;
            parameters[7].Value = model.VPM;
            parameters[8].Value = model.IS_USED;
            parameters[9].Value = model.LOT_NUMBER;
            parameters[10].Value = model.VERSION_NO;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string LOT_NUMBER, int VERSION_NO)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from pro_lot_test_data ");
            strSql.Append(" where LOT_NUMBER=@LOT_NUMBER and VERSION_NO=@VERSION_NO ");
            MySqlParameter[] parameters = {
					new MySqlParameter("@LOT_NUMBER", MySqlDbType.VarChar,50),
					new MySqlParameter("@VERSION_NO", MySqlDbType.Int32,11)			};
            parameters[0].Value = LOT_NUMBER;
            parameters[1].Value = VERSION_NO;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data GetModel(string LOT_NUMBER, int VERSION_NO)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select LOT_NUMBER,VERSION_NO,TTIME,EL_IMAGE,IV_IMAGE,PMAX,ISC,IPM,VOC,VPM,IS_USED from pro_lot_test_data ");
            strSql.Append(" where LOT_NUMBER=@LOT_NUMBER and VERSION_NO=@VERSION_NO ");
            MySqlParameter[] parameters = {
					new MySqlParameter("@LOT_NUMBER", MySqlDbType.VarChar,50),
					new MySqlParameter("@VERSION_NO", MySqlDbType.Int32,11)			};
            parameters[0].Value = LOT_NUMBER;
            parameters[1].Value = VERSION_NO;

            Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data model = new Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data DataRowToModel(DataRow row)
        {
            Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data model = new Astronergy.MES.App.Library.MySQL.Model.pro_lot_test_data();
            if (row != null)
            {
                if (row["LOT_NUMBER"] != null)
                {
                    model.LOT_NUMBER = row["LOT_NUMBER"].ToString();
                }
                if (row["VERSION_NO"] != null && row["VERSION_NO"].ToString() != "")
                {
                    model.VERSION_NO = int.Parse(row["VERSION_NO"].ToString());
                }
                if (row["TTIME"] != null && row["TTIME"].ToString() != "")
                {
                    model.TTIME = DateTime.Parse(row["TTIME"].ToString());
                }
                if (row["EL_IMAGE"] != null)
                {
                    model.EL_IMAGE = row["EL_IMAGE"].ToString();
                }
                if (row["IV_IMAGE"] != null)
                {
                    model.IV_IMAGE = row["IV_IMAGE"].ToString();
                }
                if (row["PMAX"] != null && row["PMAX"].ToString() != "")
                {
                    model.PMAX = decimal.Parse(row["PMAX"].ToString());
                }
                if (row["ISC"] != null && row["ISC"].ToString() != "")
                {
                    model.ISC = decimal.Parse(row["ISC"].ToString());
                }
                if (row["IPM"] != null && row["IPM"].ToString() != "")
                {
                    model.IPM = decimal.Parse(row["IPM"].ToString());
                }
                if (row["VOC"] != null && row["VOC"].ToString() != "")
                {
                    model.VOC = decimal.Parse(row["VOC"].ToString());
                }
                if (row["VPM"] != null && row["VPM"].ToString() != "")
                {
                    model.VPM = decimal.Parse(row["VPM"].ToString());
                }
                if (row["IS_USED"] != null)
                {
                    model.IS_USED = row["IS_USED"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select LOT_NUMBER,VERSION_NO,TTIME,EL_IMAGE,IV_IMAGE,PMAX,ISC,IPM,VOC,VPM,IS_USED ");
            strSql.Append(" FROM pro_lot_test_data ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM pro_lot_test_data ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.VERSION_NO desc");
            }
            strSql.Append(")AS Row, T.*  from pro_lot_test_data T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            MySqlParameter[] parameters = {
                    new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
                    new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
                    new MySqlParameter("@PageSize", MySqlDbType.Int32),
                    new MySqlParameter("@PageIndex", MySqlDbType.Int32),
                    new MySqlParameter("@IsReCount", MySqlDbType.Bit),
                    new MySqlParameter("@OrderType", MySqlDbType.Bit),
                    new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "pro_lot_test_data";
            parameters[1].Value = "VERSION_NO";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

